import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'
import Login from '@/views/Login'
import Category from '@/views/Category'
import Home from '@/views/Home'
import Good from '@/views/Goods'
import Cart from '@/views/Cart'
import Settlement from '@/views/Settlement'
import Pay from '@/views/Pay'
import PayCallback from '@/views/PayCallback'

// 定义路径和组件的对应关系
const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    component: Layout,
    children: [
      { path: '', component: Home }, // 如果二级路由path为空,将作为默认渲染的路由
      { name: 'category', path: 'category/:id', component: Category },
      { path: 'good/:id', component: Good },
      { path: 'cart', component: Cart },
      { path: 'settlement', component: Settlement },
      { path: 'pay', component: Pay },
      { path: 'pay/callback', component: PayCallback }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
